package com.yeung.exam;

import java.util.*;

public class 花得摆法 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int groups = sc.nextInt();
        int k = sc.nextInt();
        int count = 0;
        while (count < groups) {
            int a = sc.nextInt();
            int b = sc.nextInt();

        }
    }

    private static int baifa(int a, int b, int k) {
        return 0;
    }

    public static ArrayList<String> Permutation(String str) {
        ArrayList<String> result = new ArrayList<>();
        if (str.equals("") || str == null) return result;
        Set<String> set = new LinkedHashSet<>();
        char[] chars = str.toCharArray();
        Arrays.sort(chars);
        boolean[] vis = new boolean[chars.length];
        char[] tmp = new char[chars.length];
        permutation(0, tmp, chars, vis, set);
        result.addAll(set);
        return result;

    }

    /**
     * dfs形式遍历字符数组
     * * 利用访问数组来确定某一位置的元素是否已经访问
     * <p>
     *
     * @param index
     * @param tmp
     * @param chars
     * @param vis
     * @param set
     */
    public static void permutation(int index, char[] tmp, char[] chars, boolean[] vis, Set<String> set) {
        if (index == chars.length) {
            set.add(new String(tmp));
            return;
        }
        //每一轮选一个不同的字符(下一轮选剩下的)来进行全排列
        for (int i = 0; i < chars.length; i++) {
            if (!vis[i]) {
                tmp[index] = chars[i];
                vis[i] = true;
                permutation(index + 1, tmp, chars, vis, set);
                //回溯
                vis[i] = false;
            }
        }
    }

}
